package com.example.pufang.controller;

import com.example.common.CommonResult;
import com.example.common.PageParamRequest;
import com.example.pufang.pojo.User;
import com.example.pufang.service.UserService;
import com.example.pufang.vo.PageListVo;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin
@Api(tags = "web用户接口")
public class UserController {

    @Autowired
    private UserService userService;

    @Operation(summary = "获取分页用户列表")
    @GetMapping("/getListByPage")
    public CommonResult<PageListVo> getListByPage(PageParamRequest pageParamRequest,
                                                  String searchPhone, String searchName, String searchRealName) {
        return CommonResult.success(userService.getListByPage(pageParamRequest, searchPhone, searchName, searchRealName));
    }

    @Operation(summary = "封禁账号")
    @PostMapping("/ban")
    public CommonResult<Boolean> ban(@RequestBody User user) {
        Boolean result = userService.ban(user);
        if (result) {
            return CommonResult.success(true, "封禁成功");
        } else {
            return CommonResult.failed("封禁失败");
        }
    }

    @Operation(summary = "解封账号")
    @PostMapping("cancelBan")
    public CommonResult<Boolean> cancelBan(@RequestBody User user) {
        Boolean result = userService.cancelBan(user);
        if (result) {
            return CommonResult.success(true, "解封成功");
        } else {
            return CommonResult.failed("解封失败");
        }
    }

}
